function smallestNumber(nums) {
    function cmp(a, b) {
        let str1 = Number(String(a) + String(b))
        let str2 = Number(String(b) + String(a))
        return str1 - str2
        
    }
    nums.sort(cmp)
    return nums.join('')
}

let nums = [3, 30, 34, 5, 9]
console.log(smallestNumber(nums));